//
//  CKConnection.h
//  ConnectionKit
//
//  Created by Matthias Plappert on 13.06.09.
//  Copyright 2009 phapswebsolutions. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

#import "CKConnectionDelegate.h"

typedef enum {
	CKConnectionErrorCodeUnknownError,
	CKConnectionErrorCodeResponseError
} CKConnectionErrorCode;

@interface CKConnection : NSObject {
	NSMutableDictionary *_connections;
	NSMutableDictionary *_data;
	NSMutableDictionary *_userInfos;
	
	NSTimeInterval timeout;
	NSURLRequestCachePolicy cache;
	id <CKConnectionDelegate> delegate;
}

@property (nonatomic, assign) NSTimeInterval timeout;
@property (nonatomic, assign) NSURLRequestCachePolicy cache;
@property (nonatomic, assign) id <CKConnectionDelegate> delegate;

- (NSError *)checkResponse:(NSURLResponse *)response forAction:(NSString *)action;
- (NSError *)load:(NSString *)action synchronous:(BOOL)synchronous userInfo:(NSDictionary *)userInfo;
- (NSString *)actionForConnection:(NSURLConnection *)connection;
- (NSURLConnection *)connectionForAction:(NSString *)action;
- (NSDictionary *)userInfoForConnection:(NSURLConnection *)connection;
- (void)cancelAction:(NSString *)action;
- (void)cancelAllActions;

- (NSString *)URLForAction:(NSString *)action userInfo:(NSDictionary *)userInfo; // Returns the URL for an action
- (NSArray *)supportedResponseMIMETypesForAction:(NSString *)action userInfo:(NSDictionary *)userInfo; // Returns an array that contains all supported MIME types
- (NSURLRequest *)requestForAction:(NSString *)action userInfo:(NSDictionary *)userInfo; // Returns the request itself
- (NSError *)parse:(NSData *)data action:(NSString *)action userInfo:(NSDictionary *)userInfo; // Gets called to parse the response using a xml, JSON, ... parser

@end
